<template>
  <div>
    <div></div>
    <div>
      <el-input
        v-model="empName"
        @keydown.enter.native="initEmps"
        clearable
        @clear="initEmps"
        >搜索</el-input
      >
      <template slot-scope="scope">
        <el-button></el-button>
      </template>
      <template slot-scope="scope">
        <el-tag>{{ scope.row.contractTerm }}</el-tag>
      </template>
      <div>
        <el-pagination
          @current-change="currentchange"
          @size-change="sizeChange"
        >
        </el-pagination>
      </div>
      <div>
        <el-dialog title="提示" :visible.sync="dialogVisible" width="30%">
          <span>这是一段信息</span>
        </el-dialog>
        <el-button @click="showAddempView"></el-button>
      </div>
    </div>
    <div>
      <el-form ref="form" :model="emp" :rules="rules">
        <el-row>
          <el-col :span="8">
            <el-form-item label="姓名" prop="name">
              <el-inpu v-model="emp.name"></el-inpu>
            </el-form-item>
            <el-form-item label="性别" prop="gender">
              <el-radio-group prop="gender">
                <el-radio label="南"></el-radio>
                <el-radio label="女"></el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
          <el-col :span="8"></el-col>
          <template slot-scope="scope">
              <el-button @click="showEditEmpView(scope.row)"></el-button>
          </template>
        </el-row>
      </el-form>
      <div @click="showDepView"></div>
      <template slot-scope="scope">
          <button @click="deleteEmp(scope.row)"></button>
      </template>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
        headers:{
            Authorization.window.sessionStorage.getItem('tokenStr')
        },
      emps: [],
      //asdasdasd
      total: 0,
      currentPage: 1,
      size: 10,
      empName: "",
      dialogVisible: false,
      emp: {
        name: "",
        gender: "",
        idCard: "",
        email: " ",
      },
      visible: false,
      inputDepnName: "",
      rules:{
          name:[{required:true,message:'asda',trigger:'blur'}],
          gender:[{required:true,message:'asda',trigger:'blur'}],
          birthday:[{required:true,message:'asda',trigger:'blur'}],
          address:[{required:true,message:'asda',trigger:'blur'}],
          phone:[{required:true,message:'asda',trigger:'blur'}],
          email:[{required:true,message:'asda',trigger:'blur'},{type:'email',message:'成功了吗'}],
          idCard:[{required:true,message:'asda',trigger:'blur'}],
      }
    };
  },
  mounted() {
    this.initDate;
  },
  methods: {
      showEditEmpView(data){
          this.title ='编辑员工信息'
          this.emp = data
      },
      deleteEmp(data){

      },
    doAddEmp() {
        if(this.emp.id){
            this.$refs['empForm'].validate(valid =>{
            if(valid){
                this.putRequest("url", this.emp).then((resp) => {
        if (resp) {
          this.dialogVisible = false;
          this.initEmps();
        }
      });
            }
        })
        }else{
            this.$refs['empForm'].validate(valid =>{
            if(valid){
                this.postRequest("url", this.emp).then((resp) => {
        if (resp) {
          this.dialogVisible = false;
          this.initEmps();
        }
      });
            }
        })
        }
      
    },
    handeleNodeClick(data) {
      this.inputDepnName = data.name;
      this.emp.deapartmenId = data.idCard;
      this.visible = !this.visible;
    },
    showDepView() {
      this.visible = !this.visible;
    },
    getmaxworkid() {
      this.getRequest("url").then((resp) => {
        if (resp) {
          this.emp.workID = resp.obj;
        }
      });
    },
    initPositions() {
      this.getRequest("url").then((resp) => {
        if (resp) {
          this.positions = resp;
        }
      });
    },

    initDate() {
      if (!window.sessionStorage.getItem("nations")) {
        this.getRequest("url").then((resp) => {
          if (resp) {
            this.nations = resp;
            window.sessionStorage.setItem("nations");
          }
        });
      } else {
        this.nations = JSON.parse(window.sessionStorage.getItem("nations"));
      }
    },
    initEmps() {
      this.loading = true;
      this.getRequest(
        "url/?currentPage=" +
          this.currentPage +
          "&size=" +
          this.size +
          "&name=" +
          this.empName
      ).then((resp) => {
        this.loading = false;
        if (resp) {
          this.emps = resp.data;
          this.total = tesp.total;
        }
      });
    },
    currentchange(currentPage) {
      this.currentPage = currentPage;
      this.initEmps();
    },
    sizeChange(size) {
      this.size = size;
      this.initEmps();
    },
    showAddempView() {
        this.title = "添加员工"
      this.dialogVisible = true;
        
    },
  },
};
</script>

<style>
</style>